$(function () {
	findBytatus(0,1);
})


//查询所有优惠券
function findBytatus(status,userId){



	$.ajax({
		headers:{
			token: getCookie("token")
		},
		type: "post",
		url: "http://cn.pn.com/api-pn/user/Coupon/v/findByStatus",
		data:{status:status,userId:userId},
		dateType:"json",
		async:false,
		success: function (data) {
			$("#couponlist").html("");
			$.each(data,function(i,e){
				var startTime=formatDate(new Date(e.startTime));
				var endTime=formatDate(new Date(e.endTime));
				$("#couponlist").append("<div class=\"bottom layui-col-xs6 layui-col-sm6 layui-row-md6\">\n" +
					"\t\t\t\t\t<div class=\"yhj\">\n" +
					"\t\t\t\t\t\t<div class=\"yhj_l\">\n" +
					"\t\t\t\t\t\t\t<small>￥</small>"+e.couponValue+"\n" +
					"\t\t\t\t\t\t</div>\n" +
					"\t\t\t\t\t\t<div class=\"yhj_r\">\n" +
					"\t\t\t\t\t\t\t<div class=\"yhj_r_t\">\n" +
					"\t\t\t\t\t\t\t\t<div class=\"d\">"+e.couponName+" </div>\n" +
					"\t\t\t\t\t\t\t\t<div></div>\n" +
					"\t\t\t\t\t\t\t</div>\n" +
					"\t\t\t\t\t\t\t<div class=\"yhj_r_b layui-col-md8\">\n" +
					"\t\t\t\t\t\t\t\t有效期："+startTime+" - "+endTime+"\n" +
					"\t\t\t\t\t\t\t</div>\n" +
					"\t\t\t\t\t\t\t<div  style=\"display: none\"></div>\n" +
					"\t\t\t\t\t\t</div>\n" +
					"\t\t\t\t\t</div>\n" +
					"\t\t\t\t</div>")
			})
		}
	})
}


function formatDate(now) {
	var year=now.getFullYear();
	var month=now.getMonth()+1;
	var date=now.getDate();
	/*    var hour=now.getHours();
        var minute=now.getMinutes();
        var second=now.getSeconds();*/
	return year+"-"+month+"-"+date/*+" "+hour+":"+minute+":"+second*/;
}
$('#hy p').click(function(){
	$('#hy p').css({'border-bottom':'0px solid #ff2661','color':'#000'})
	$(this).css({'border-bottom':'2px solid #ff2661','color': '#ff2661'})
})

$("#aaa").click(function () {
	findBytatus(0,1);
})

$("#bbb").click(function () {
	findBytatus(1,1);
})

/*$('#dh').click(function(){
	$('#xs,#zz').css({'display':'block'});
})
$('#xx').click(function(){
	$('#xs,#zz').css({'display':'none'})
})
$('#hy p').eq(1).click(function(){
	$('.yhj').css({'display':'none'})
})
$('#hy p').eq(0).click(function(){
	$('.yhj').css({'display':'flex'})
})*/
